<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class CarRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'number' => 'required|max:20',
//            'ownership' => 'required',
            'company_id' => 'required'
        ];
    }

    /**
     * 验证提示信息
     * @return array
     * @Author 姿势就是力量
     */
    public function messages()
    {
        return [
            'number.required' => '车牌号不能为空',
            'number.max' => '车牌号长度只能在20个字符之内',
//            'ownership.required' => '请选择车辆所属权',
            'company_id.required' => '请选择管理公司',
        ];
    }


    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'code' => 0,
            'data' => [],
            'msg' => $validator->errors()->first()
        ], 400));
    }
}
